home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / video / seqgrab / cv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.6 KB  |  114 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.     cv.c - Address/time type conversion routines.
  19.  
  20.     Tim Heidmann, Silicon Graphics
  21.  
  22.     Created    January 25, 1994
  23.     Last Edit  January 27, 1994
  24. */
  25.  
  26. #include <stdio.h>
  27. #include <sys/time.h>
  28. #include "cv.h"
  29.  
  30. #define FPS     30
  31. #define FPM   1800
  32. #define FPH 108000
  33.  
  34. int cv_errno;
  35.  
  36. int
  37. mc_convert(int fromType, int toType, ...) {
  38.     int *arg;
  39.     int *pFrame, iFrame;
  40.     int h, m, s, f;
  41.     char *cptr;
  42.     char buf[64], buf2[64], *b, *c;
  43.     int pad;
  44.     struct timeval *tvp;
  45.  
  46.     cv_errno = 0;
  47.     arg = &toType + 1;
  48.     switch (toType) {
  49.  
  50.     case MC_NTSC_FRAME:
  51.     if (fromType != MC_NTSC_TC) {
  52.         cv_errno = CV_UNSUPPORTED; return -1; }
  53.  
  54.     cptr = (char *)(arg[0]);
  55.     pFrame = (int *)(arg[1]);
  56.  
  57.     /* Remove all but numerics */
  58.     for (b = buf, c = cptr; *c != '\0'; c++)
  59.         if (*c >= '0' && *c <= '9') *(b++) = *c;
  60.     *b = '\0';
  61.  
  62.     /* Pad to hhhhmmssff */
  63.     strcpy(buf2, "0000000000");
  64.     pad = 10 - strlen(buf);
  65.     if (pad >= 0)
  66.         strcpy(buf2 + pad, buf);
  67.     else
  68.         strcpy(buf2, buf - pad);
  69.  
  70.     /* Scan it! */
  71.     sscanf(buf2, "%4d%2d%2d%2d", &h, &m, &s, &f);
  72.     *pFrame = FPH * h + FPM * m + FPS * s + f;
  73.     return 0;
  74.  
  75.  
  76.     case MC_NTSC_TC:
  77.     if (fromType != MC_NTSC_FRAME) {
  78.         cv_errno = CV_UNSUPPORTED; return -1; }
  79.  
  80.     iFrame = arg[0];
  81.     cptr = (char *)(arg[1]);
  82.  
  83.     if (iFrame < 0)
  84.         cptr[0] = '\0';
  85.     else {
  86.         h = iFrame / FPH;
  87.         iFrame -= h * FPH;
  88.         m = iFrame / FPM;
  89.         iFrame -= m * FPM;
  90.         s = iFrame / FPS;
  91.         iFrame -= s * FPS;
  92.         sprintf(cptr, "%02d:%02d:%02d:%02d", h, m, s, iFrame);
  93.     }
  94.     return 0;
  95.  
  96.  
  97.     case MC_TIME:
  98.     if (fromType != MC_NTSC_FRAME) {
  99.         cv_errno = CV_UNSUPPORTED; return -1; }
  100.  
  101.     iFrame = arg[0];
  102.     tvp = (struct timeval *)(arg[1]);
  103.     tvp->tv_sec = (int)(iFrame / NTSC_FRAMES_PER_SEC);
  104.     tvp->tv_usec = NTSC_USEC_PER_FRAME *
  105.         (iFrame - (int)(tvp->tv_sec * NTSC_FRAMES_PER_SEC));
  106.     return 0;
  107.  
  108.  
  109.     default:
  110.     cv_errno = CV_UNSUPPORTED;
  111.     return -1;
  112.     }
  113. }
  114.